package com.ydj.app.entity;

import com.google.gson.reflect.TypeToken;
import com.ydj.app.enumerate.ForecastQuestionCateEnum;
import com.ydj.app.protocol.dto.ForecastQaItemDto;
import com.ydj.framework.mysql.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
@Entity
@Table(name = "forecast_result",
        indexes = {@Index(name = "idx_webUserId", columnList = "webUserId")})
@org.hibernate.annotations.Table(appliesTo = "forecast_result", comment = "预测结果")
public class ForecastResult extends BaseEntity {
    @Column(columnDefinition = "bigint comment '用户ID'", nullable = false)
    private Long webUserId;

    @Column(columnDefinition = "tinyint comment '预测类别'", nullable = false)
    private ForecastQuestionCateEnum cate;

    @Column(columnDefinition = "int comment '成功率'")
    private Integer rate;

    @Column(columnDefinition = "varchar(100) comment '联系方式'")
    private String contact;

    @Column(columnDefinition = "varchar(300) comment 'AI返回的结果文字'")
    private String result;

    @Column(columnDefinition = "text comment '问题和答案的JSON'")
    private String qaJson;

    public List<ForecastQaItemDto> getQaList() {
        return gson.fromJson(qaJson, new TypeToken<List<ForecastQaItemDto>>() {}.getType());
    }

    public ForecastResult setQaList(List<ForecastQaItemDto> qaList) {
        qaJson = gson.toJson(qaList);
        return this;
    }
}